import { defineStore } from 'pinia';
import { getToken, removeToken } from '@/utils/token';
import { toLogin } from '@/utils/auth';

export const useUserStore = defineStore('user', {
	state() {
		return {
			info: {},
			accessToken: getToken(),
			permissions: [],
			roles: [],
		};
	},
	getters: {
		userId() {
			return this.info?.userId;
		},
		name() {
			return this.info?.name;
		},
		avatar() {
			return this.info?.avatar;
		},
		role() {
			return this.info?.role || [];
		},
		token() {
			return this.accessToken;
		},
		getPermissions() {
			return this.permissions;
		},
		getRoles() {
			return this.roles;
		},
	},
	actions: {
		setInfo(info = {}) {
			this.info = { ...this.info, ...info };
		},
	},
});
